package com.shuql.zklock.impl;

import com.shuql.zklock.ZkLock;

public abstract class AbstrackLock implements ZkLock {

    /**
     * 上锁
     *
     * @param path zk节点路径
     */
    public void lock(String path) {
        if (!tryLock(path)) {
            waitLock(path);
            lock(path);
        }
    }

    /**
     * 尝试加锁
     *
     * @param path
     * @return
     */
    public abstract boolean tryLock(String path);

    /**
     * 等待加锁
     *
     * @param path
     */
    public abstract void waitLock(String path);
}
